package com.wtwd.device.model.vo;


import com.wtwd.common.base.model.BaseRespCode;
import com.wtwd.device.constant.RespCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 响应数据，有额外data
 */
@ApiModel(value = "接口返回对象", description = "接口返回对象")
public class RespEntity<T>  {
    /**
     * 返回消息
     */
    @ApiModelProperty(value = "返回消息")
    private String msg = BaseRespCode.SUCCESS_MSG;

    /**
     * 返回代码
     */
    @ApiModelProperty(value = "返回代码")
    private  int code = BaseRespCode.SUCCESS_CODE;
    private T data;

    public RespEntity(){

    }

    public RespEntity(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public RespEntity(RespCode respCode){
        this.code = respCode.getCode();
        this.msg = respCode.getMsg();
    }

    public RespEntity(RespCode respCode, T data){
        this(respCode);
        this.data = data;
    }


    public static <T> RespEntity<T> success(BaseRespCode respCode, T data) {
        RespEntity<T> r = new RespEntity<>();
        r.setCode(respCode.getCode());
        r.setMsg(respCode.getMsg());
        r.setData(data);
        return r;
    }

    public RespEntity(int code, String msg){  // 针对导入导出异常使用
        this.code = code;
        this.msg = msg;
    }
    public RespEntity(int code, String msg, T data) {  // 针对导入导出异常使用
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}